package Dinamica;


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Locale;


class UnrealTournament {

	public static float cu(){
		q = 1-p;
		return q;
	}
	
	public static int n = 0;
	public static BigInteger llamados = BigInteger.ZERO;
	public static boolean error = false;
	public static float p = 0, q = 0;
	public static float[][][] matriz = new float[1001][1001][1];
	public static BigInteger[][] llamadosB = new BigInteger[1001][1001];
	
	public static float P(int i, int j){
		
		if(matriz[i][j][1]!=0){
			if (i==0) {matriz[0][j][0] = 1; llamadosB[0][j].add(BigInteger.ONE); return 1;}
			else if (j==0) {matriz[i][0][0] = 0; llamadosB[i][j].add(BigInteger.ONE); return 0;}
		}
		
		else {
			matriz[i][j][0] = p*P(i-1,j) + q*P(i,j-1);
			llamados =  llamadosB[i-1][j].add(llamadosB[i][j-1]);
			llamadosB[i][j] = llamados.add(BigInteger.ONE);
			show();
		}
		return matriz[i][j][0];
	}
	
	
	public static float PDin(int k, int l){
		for(int i = 0 ; i!=k+1;i++){
			for(int j=0; j!=l+1; j++){
				if(i==0){
					llamadosB[i][j] = BigInteger.ONE;
					matriz[i][j][0] = 1;
				}
				else if(j==0){
					llamadosB[i][j] = BigInteger.ONE;
					matriz[i][j][0] = 0;
				}
				else{
					matriz[i][j][0] = p*matriz[i-1][j][0] + q*matriz[i][j-1][0];
					llamadosB[i][j] = llamadosB[i-1][j].add(llamadosB[i][j-1].add(BigInteger.ONE));
				}
				//show();
			}
		}
		return 0;
	}
	

	
	
	
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String linea = bf.readLine();
		while(linea.length()!=0){
				error = false;
				LinkedList<Point> save = new LinkedList<Point>();
				int k = 0, maxi = 0, maxj = 0;
				p = Float.parseFloat(
						linea.substring(0, 
								linea.indexOf((' '))));
				k = Integer.parseInt(linea.substring(linea.indexOf(' ')+1));
				if(!error)cu();
				
				while(k!=0){
					linea = bf.readLine();
					int i = -1, j=-1;
					i = Integer.parseInt(linea.substring(0,linea.indexOf(' ')));
					j = Integer.parseInt(linea.substring(linea.indexOf(' ')+1,linea.length()));
					save.add(new Point(i,j));
					if(i>maxi) maxi = i;
					if(j>maxj) maxj = j;
					
					k--;
				}
				if(!error)PDin(maxi,maxj);
				//show();
				llamados=BigInteger.ZERO;
					for(Point p: save){
						if(p.x != 0 && p.y !=0){
							System.out.println("");
							System.out.printf(Locale.US,"%.5f\n", matriz[p.x][p.y][0]);
							System.out.print(llamadosB[p.x][p.y].subtract(BigInteger.ONE));
						}
						else System.out.print("\n-1.00000\n0");
					}
				
					
				if(!bf.ready()) break;
				linea = bf.readLine();
				System.out.println("");
				
			
		}
	}
	
	
	
	
	public static void show(){
		for(int i=0; i!=10; i++){
			for(int j=0; j!=10; j++) System.out.print(matriz[i][j][1]+" ");
			System.out.println("");
		}
		System.out.println("");
	}
}
